#ifndef FREETYPE_FONT_H
#define FREETYPE_FONT_H

// FreeType Headers
#include <ft2build.h>
#include <freetype2/freetype/freetype.h>
#include <freetype2/freetype/ftglyph.h>
#include <freetype2/freetype/ftoutln.h>
#include <freetype2/freetype/fttrigon.h>
#include <string>
#include <map>

#include "GLee.h"
#include "geom.h"

class GLSLProgram;

class FreeTypeFont 
{
public:
    FreeTypeFont(const std::string& fontName, int screenWidth, int screenHeight, 
                 int fontSize, const Color& color=Color(1.0f, 1.0f, 1.0f, 1.0f));
    ~FreeTypeFont();

    bool initialize();
    void printString(const std::string& str, float x, float y);
    void printString(const std::string& str, float x, float y, const Color& color);
    float textLength(const std::string& str);

    int fontSize(void) const { return m_fontSize; }
    const std::string& fontName(void) { return m_fontName; }

    const Color& getColor(void) const { return m_color; }
    void setColor(const Color& color);

private:
    GLuint m_textureID[128]; //Store room for the character textures

    int m_fontSize;
    Color m_color;
    int m_screenWidth;
    int m_screenHeight;
    std::string m_fontName;

    GLuint m_texCoordBuffer;
    GLuint m_vertexBuffer;
    GLuint m_colorBuffer;

    void setOrthoMode();
    void unsetOrthoMode();
    bool generateCharacterTexture(unsigned char ch, FT_Face fontInfo);

    static GLSLProgram* m_shaderProgram;

    std::map<char, std::pair<int, int> > m_glyphDimensions;
    std::map<char, std::pair<int, int> > m_glyphPositions;
    std::map<char, int> m_glyphAdvances;
};

#endif
